home *** CD-ROM | disk | FTP | other *** search
-
-
-
- 134
-
- CHAPTER 14 - ZOOM
-
-
- There are only a couple of reasons for working at the assembler
- level. Perhaps you're curious about how the PC functions at the
- machine level. Maybe you want to optimize a time consuming
- section of code. Maybe you want to work easily with the DOS
- function calls and the BIOS calls (which will be introduced in a
- later chapter). Or maybe you want raw speed.
-
- Every time that I enter:
-
- >dir /w
-
- and watch DOS meander its way down the screen at a leisurely
- pace, I think "Can't the computer go any faster?" Let's find
- out. This is going to be a short chapter. Make a copy of
- template.asm, and we'll call it zoom.asm. This is going to
- overwrite the entire screen 200 times.{1}
-
- Before we write to the screen, we need to know where the screen
- is. When IBM designed the structure of the PC, they decided to
- put the memory for the monochrome card in one place and the
- memory for the color card in another place - apparently they
- thought you might want to have both a color monitor and a
- monochrome monitor running at the same time. The color monitor is
- in segment 0B800 at offset 0, and the monochrome monitor is in
- segment 0B000 at offset 0. We need to put the correct number into
- the program, so you need to know whether you have a color card or
- a monochrome card. If one segment number doesn't work, you can
- try the other.
-
- TEMPLATE.ASM
- ; - - - - - - - - - - START CODE BELOW THIS LINE
- call show_regs_and_wait ; {2}
- ; we are about to start
- ; this marks the time
-
- mov ax, 0B800h ; color seg. 0B000h is mono seg
- mov es, ax ; es is at video card segment
- mov cx, 2 ; do this whole thing twice
- outer_loop:
- ____________________
-
- 1 It is now time for you to go out and get a book about the
- internal structure and i/o interface of the PC. One good book is
- "The Peter Norton Programmer's Guide To The IBM PC", by guess
- who? It is clearly written and a good introduction. Another
- quality book is "DOS Programmer's Reference" by Terry Dettmann.
- It is very systematically laid out and is more techie oriented.
-
- 2 We need to initialize the video card to make sure it is in
- the right place. This is the easiest way. The registers
- themselves mean nothing to us.
-
- ______________________
-
- The PC Assembler Tutor - Copyright (C) 1989 Chuck Nelson
-
-
-
-
- Chapter 14 - Zoom 135
- _________________
-
- push cx ; save for outer loop instruction
- mov cx, 100 ; 100 repeats ; zoom_loop count
- mov al, '0' ; 100 characters starting at '0'
- mov ah, 07h ; black background, white letters
-
- zoom_loop: ; draw the screen 100 times
- push cx
- mov cx, 2000 ; 80 X 25 screen is 2000 words long
- mov si, 0 ; start at offset 0000.
-
- inner_loop: ; inner loop - fill the screen - 2000 words
- mov es:[si], ax
- add si, 2
- loop inner_loop
-
- inc al ; next higher ASCII character
- pop cx ; zoom_loop count
- loop zoom_loop
-
- pop cx ; outer_loop count
- loop outer_loop
-
- call get_continue ; finished - this is for timing
- ; - - - - - - - - - - END CODE ABOVE THIS LINE
-
-
- Show_regs_and_wait resets the video card, so we use it to make
- sure the video memory is set at offset 0000. It then waits for
- ENTER. At the end, get_continue waits for ENTER.{3} This way you
- can mark the beginning and the end in order to time it. We set
- the ES segment to the video segment. This is different depending
- on whether you have a monochrome card or a color card. The
- monochrome segment is at 0B000h and the color card is at 0B800h.
- You need to know which kind of card you have so you can put the
- right number into ES via AX.
-
- Since the normal segment for SI is the DS segment, we need to put
- in a segment override to use SI with the ES segment.
-
- We start with the ASCII character '0' and then do the next 99
- characters in increasing ASCII sequence. Technically, ASCII
- characters end at 127, but the PC extended characters go up to
- 255, so we will start with ASCII 48d and end with ASCII 147d. The
- zoom_loop changes the character 100 different times, and the
- inner_loop fills the screen. That 07h in AH means that we will
- have white characters on a black background. The outer loop has a
- count of 2. This should be adjusted. If you have a medium speed
- machine make it 4 (400 screen fills) and if you have a high speed
- machine make it 8 (800 screen fills).
-
- ____________________
-
- 3 That is its mission in life. It is there so that you can
- time blocks of code. If you want to find out how long some code
- takes, repeat it 10,000 (or whatever is appropriate) times and
- put get_continue in front of it and behind it. That way you can
- control the start and mark the finish.
-
-
-
-
- The PC Assembler Tutor 136
- ______________________
-
- When this is done, the screen will be filled with characters so
- you will need to use the DOS command
-
- > cls
-
- to clear the screen for anything else.
-
- When it is all assembled and linked, get a cup of coffee and a
- wristwatch with a second hand and we'll time it. Divide by 200
- (or 400 or 800) to find out how long it takes to fill one screen.
- If the characters are not on your screen, you probably have the
- wrong segment address for your video card, so try the other one.
- Are you ready to time it? Then ready, set, go.
-
- Hmmm. On my machine 200 repeats takes about 4 seconds, while the
- dir command takes about 1 second for one screen. That means that
- zoom.asm is about 50 times faster. That's the difference between
- someone running a 4 minute mile and someone running a 3hr. 20min.
- mile. This is one of the reasons people like to work at the
- assembler level.
-
-